<?php

class Game_screen_renderer {

    public function __construct() {
        $this->CI = & get_instance();
        $this->CI->load->model('character_model');
        $this->CI->load->model('mapcoord_model');
        $this->CI->load->model('map_model');
    }

    public function render($logged_in) {

        $character_location = $this->CI->mapcoord_model->getById($logged_in->mapCoordId);
        $startX = $character_location->x - 9;
        $startY = $character_location->y - 4;
        $maxX = $character_location->x + 9;
        $maxY = $character_location->y + 4;
        $xCalc = 1;
        $yCalc = 1;
        
        $emptySpace = new stdClass();
        $emptySpace->imageUrl =  "water.jpg";
        
        $grid = null;
        
        for ($i = $startY; $i <= $maxY; $i++) {
            for ($j = $startX; $j <= $maxX; $j++) {
                if ($xCalc > 19) {
                    $xCalc = 1;
                }
                $checkSpace = $this->CI->mapcoord_model->getByCoords($j, $i);
                if ($checkSpace != null) {
                    $grid[$yCalc][$xCalc] = $checkSpace;
                } else {
                    $grid[$yCalc][$xCalc] = $emptySpace;
                }
                $xCalc = $xCalc + 1;
            }
            $yCalc = $yCalc + 1;
        }
        
        return $grid;
    }
    
}

?>
